package com.onpositive.wiki3.db.impl;

import java.io.File;

import com.onpositive.wiki3.db.catmodel.Categories;
import com.onpositive.wiki3.db.catmodel.Category;
import com.onpositive.wiki3.db.catmodel.matches.classify.RelationConstants;
import com.onpositive.wiki3.db.catmodel.matches.classify.RelationStore;

public class LeafsReadder {

	public static void main(String[] args) {
		final WikiDBImpl wikiDBImpl = new WikiDBImpl("C:/work/content");
		try {
			RelationStore ss = new RelationStore(wikiDBImpl);
			System.setProperty("wordnet.database.dir", "C:/work/wn/dict");

			final Categories c0 = new Categories(wikiDBImpl, new File(
					"C:/work/content/relation.dat"), true);
			Categories categories = ss.get(RelationConstants.IS_A);
			for (Category q : c0) {
				if (!q.hasChildren()) {
					int[] parents = q.getParents();
					for (int z : parents) {
						Category category = categories.get(z);
						if (category != null) {
							categories.registerChild(z, q.id());
						}
					}
				}
			}
			ss.save();
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
}
